# plotting example trials
trials = c(1, 3, 9, 11, 18, 34, 25, 10)
labels = 1:8
df.plot = df.aggregate %>%
mutate(choice = str_replace(choice, "trees", "T"),
choice = str_replace(choice, "fish", "F"),
item = str_c(question, choice),
item = str_replace(item, "trees", "t"),
item = str_remove(item, "_strength"),
item = str_remove(item, "_choice"),
question_type = str_extract(question, "trees|strength|choice")) %>%
filter(trial %in% trials) %>%
mutate(trial = factor(trial,
levels = trials,
labels = str_c("trial ", labels)))
func_load_image = function(situation){
readPNG(str_c("../../figures/stimuli/trial_", situation, ".png"))
}
# linking images and clips
df.trials = df.plot %>%
distinct(trial) %>%
arrange(trial) %>%
mutate(number = trials,
grob = map(.x = number, .f = ~ func_load_image(situation = .x)),
label = str_c("trial ", number))
df.text = df.plot %>%
distinct(trial) %>%
arrange(trial) %>%
mutate(x = -Inf,
y = 1.2,
label = 1:n())
# plotting
ggplot(data = df.plot,
mapping = aes(x = item,
y = value)) +
geom_col(data = df.plot %>%
filter(index == "people"),
mapping = aes(fill = question_type,
linetype = question_type),
alpha = 0.5,
color = "black") +
geom_linerange(mapping = aes(ymin = low,
ymax = high),
size = 1.5) +
geom_point(data = df.plot %>%
filter(index %in% c("rationality", "pivotality",
"mixture")) %>%
mutate(index = factor(index, levels = c("rationality", "pivotality",
"mixture"))),
mapping = aes(shape = index,
fill = index),
position = position_dodge(width = 0.5),
color = "black",
stroke = 1,
size = 4) +
geom_custom(data = df.trials,
mapping = aes(data = grob,
x = -Inf,
y = Inf),
grob_fun = function(x) rasterGrob(x,
interpolate = T,
vjust = -0.05,
hjust = 0)) +
geom_text(data = df.text,
mapping = aes(x = x,
y = y,
label = label),
hjust = -0.5,
size = 20,
color = "white") +
facet_wrap(~trial,
labeller = labeller(label),
scales = "free_x",
nrow = 2) +
labs(linetype = "question",
shape = "model") +
coord_cartesian(clip = "off",
ylim = c(0, 1)) +
scale_y_continuous(breaks = seq(0, 1, 0.25),
labels = seq(0, 100, 25),
expand = expansion(add = c(0, 0))) +
scale_shape_manual(values = c(21, 23, 24)) +
scale_linetype_manual(values = rep(1, 3)) +
scale_fill_manual(breaks = c("choice", "strength", "trees",
"rationality", "pivotality", "mixture"),
values = c(choice = "gray80",
strength = "gray40",
trees = "gray0",
rationality = "blue",
pivotality = "red",
mixture = "purple")) +
theme(legend.position = "bottom",
legend.title = element_text(size=30),
legend.text = element_text(size=25),
panel.grid.major.y = element_line(),
axis.text.y = element_text(size = 25),
axis.text.x = element_text(size = 25),
axis.title = element_blank(),
strip.background = element_blank(),
strip.text = element_blank(),
panel.background = element_rect(fill = NA, color = "black"),
panel.spacing.x = unit(0.5, "cm"),
panel.spacing.y = unit(7, "cm"),
plot.margin = margin(t = 7, l = 0.2, r = 0.2, b = 0.1, unit = "cm")) +
guides(fill = F,
linetype = guide_legend(override.aes = list(fill = c("gray80",
"gray40",
"gray0"))),
shape = guide_legend(override.aes = list(fill = c("blue", "red", "purple"),
size = 8)))
# ggsave("../../figures/plots/selection.pdf",
# width = 20,
# height = 13)